// created by lupo
// created at 2017/07/21

#include <stdio.h>
#include "utils.h"

UTILS_NAMESPACE_BEGIN

std::vector<std::string> run_cmd(const std::string& cmd, bool need_output/* = true*/)
{
    std::vector<std::string> ret;
	if (cmd.empty()) {
		return ret;
	}

	FILE* fp = popen(cmd.c_str(), "r");
	if (fp == NULL) {
		return ret;
	}

    if (need_output) {
        char buf[32];
        while (fgets(buf, sizeof(buf)/sizeof(char), fp) != NULL) {
            ret.push_back(buf);
        }
    }

	pclose(fp);
	return ret;
}


UTILS_NAMESPACE_END